package com.pactera.asmp.server.dao;

import com.pactera.asmp.server.entity.DeviceExcetimeDataDTO;
import com.pactera.asmp.server.entity.ProjectStatisticsDataDTO;
import com.pactera.asmp.server.entity.TaskDTO;
import com.pactera.asmp.server.entity.TaskExceTimeDataDTO;
import com.pactera.asmp.server.entity.TaskExecDTO;
import com.pactera.asmp.server.entity.TaskExeingDTO;
import com.pactera.asmp.server.entity.TaskSearchDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ProjectName: asmp-server
 * @Package com.pactera.asmp.server.dao
 * @ClassName: TestTaskMapper
 * @Description: TestTaskMapper
 * @Date 2020/07/14 17:12
 * @Author lvzhiqiang
 * @Version 1.0
 */
@Mapper
public interface TaskMapper {

    List<TaskDTO> getTaskList(TaskSearchDTO taskSearchDTO);

    List<TaskDTO> getMonkeyTaskList(TaskSearchDTO taskSearchDTO);

    TaskDTO getTaskById(Integer taskId);
    TaskDTO getTaskHistoryById(@Param("taskId") Integer taskId);

    List<TaskDTO> getTaskHistListByParentid(TaskSearchDTO taskSearchDTO);

    int insert(TaskDTO taskDTO);
    int insertHistory(TaskDTO taskDTO);
    int taskFailById(@Param("id") Integer id, @Param("failReason") String failReason);
    int taskHistoryFailById(@Param("id") Integer id, @Param("failReason") String failReason);

    int execTask(TaskExecDTO taskExecDTO);
    int execTaskHistory(TaskExecDTO taskExecDTO);

    int execTaskProcessTimes(@Param("id") Integer id,@Param("times") Integer times);
    int execTaskProcessTimesHistory(@Param("id") Integer id,@Param("times") Integer times);

    int cancelTask(Integer id);
    int cancelTaskHistory(Integer id);

    int triggerTaskJob(Integer taskId);
    int triggerTaskHistoryJob(Integer taskId);

    int interrupterWhenExecing(String duid);
    int interrupterWhenExecingHistory(String duid);
    List<TaskDTO> getTaskHistoryByInterrupterWhenExecing(@Param("duid") String duid);

    List<TaskDTO> getTaskJobTriggerId(@Param("parentId") Integer parentId);

    int removeTaskJob(Integer taskId);
    int removeTaskHistoryJob(Integer taskId);

    int update(TaskDTO taskDTO);
    int updateHistory(TaskDTO taskDTO);

    List<TaskDTO> getCancleTaskPedding(Integer taskId);

    TaskDTO getLastTaskHistoryByTaskId(Integer taskId);

    TaskDTO getTaskUserInfoById(Integer taskId);

    List<TaskExeingDTO> getTaskExeingByProjectId(Integer projectId);


    int taskExec(Integer id);
    int taskHistoryExec(Integer id);

    TaskDTO getTaskHistoryById2(Integer taskId);

    /**
     * 根据 parentId 获取计划任务列表
     * @param parentId
     * @return
     */
    List<TaskDTO> queryByProjectId(@Param("parentId") Integer parentId);

    List<TaskDTO> queryByProjectIdAndStatus(@Param("projectId") Integer projectId, @Param("status") Integer status);

    List<TaskDTO> queryHistoryByDuids(@Param("duids") List<String> duids, @Param("projectId") Integer projectId);

    ProjectStatisticsDataDTO queryTaskExeTimeByProjectId(@Param("projectId") Long projectId);

    List<TaskDTO> getTaskHistoryListByParentids(@Param("parentids") List<Integer> parentids);

    ProjectStatisticsDataDTO summaryTaskByProjectId(@Param("projectId") Integer projectId);

    List<ProjectStatisticsDataDTO> summaryTaskByMonth(@Param("startDateTime") LocalDateTime startDateTime, @Param("endDateTime") LocalDateTime endDateTime);

    List<DeviceExcetimeDataDTO> selectExceTimeByMasterComputer(@Param("startDateTime") LocalDateTime startDateTime, @Param("endDateTime") LocalDateTime endDateTime);

    List<DeviceExcetimeDataDTO> selectExceTimeByProjectId(@Param("startDateTime") LocalDateTime startDateTime, @Param("endDateTime") LocalDateTime endDateTime);

    List<TaskExceTimeDataDTO> summaryAllTaskExceTimeByMasterComputer(@Param("startDateTime") LocalDateTime startDateTime, @Param("endDateTime") LocalDateTime endDateTime);

    Long summaryTaskCountByProjectId(@Param("projectId") Integer projectId);

}
